import 'package:flutter/material.dart';

import './tabs/Apex.dart';
import './tabs/Epic.dart';
import './tabs/GitLab.dart';
import './tabs/Steam.dart';
import './tabs/Message.dart';

class TabsXy extends StatefulWidget {
  const TabsXy({super.key});

  @override
  State<TabsXy> createState() => _TabsXyState();
}

class _TabsXyState extends State<TabsXy> {
  int indexIcon = 0;
  List<Widget> list = [
    EpicPage(),
    ApexPage(),
    GitLabPage(),
    MessagePage(),
    SteamPage(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Flutter App", style: TextStyle(color: Colors.white)),
        backgroundColor: Colors.deepPurple,
      ),
      body: list[indexIcon],
      drawer: Drawer(
        child: Text("我是左侧边栏"),
      ),
      endDrawer: Drawer(
        child: Text("我是右侧边栏"),
      ),
      // 底部菜单
      bottomNavigationBar: BottomNavigationBar(
        // 点击选择的菜单
        currentIndex: indexIcon,
        // 菜单样式 >=4 时需要加上
        type: BottomNavigationBarType.fixed,
        onTap: (index) {
          setState(() {
            indexIcon = index;
          });
        },
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"),
          BottomNavigationBarItem(
            icon: Icon(Icons.settings),
            label: "Settings",
          ),
          BottomNavigationBarItem(icon: Icon(Icons.add), label: "Add"),
          BottomNavigationBarItem(icon: Icon(Icons.message), label: "Message"),
          BottomNavigationBarItem(icon: Icon(Icons.person), label: "Person"),
        ],
      ),
      // 悬浮按钮
      floatingActionButton: Container(
        width: 60,
        height: 60,
        padding: EdgeInsets.all(4),
        margin: EdgeInsets.only(top: 8),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(30),
        ),
        child: FloatingActionButton(
          backgroundColor: indexIcon == 2 ? Colors.deepPurpleAccent : Colors.white,
          onPressed: () {
            setState(() {
              indexIcon = 2;
            });
          },
          // 将圆角矩形改为圆形
          shape: const CircleBorder(),
          child: Icon(Icons.add, color: indexIcon == 2 ? Colors.white : Colors.deepPurpleAccent),
        ),
      ),
      // 悬浮按钮位置
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
    );
  }
}
